package com.deer.wms.base.system.web.ware;

import com.deer.wms.base.system.dao.ware.DeviceMapper;
import com.deer.wms.base.system.model.bill.BillInSapDetailDto;
import com.deer.wms.base.system.model.bill.DeviceManager;
import com.deer.wms.base.system.model.ware.Customer;
import com.deer.wms.common.annotation.Log;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.core.text.Convert;
import com.deer.wms.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**机台CRUD*/
@Controller
@RequestMapping("/system/device")
public class DeviceController extends BaseController {
    private String prefix = "system/device";
	
	@Autowired
	private DeviceMapper deviceMapper;

	@GetMapping()
	public String DeviceManager() {
		return prefix + "/device";
	}
	
	/*机台列表*/
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(DeviceManager deviceManager) {
		startPage();
        List<DeviceManager> list = deviceMapper.selectDeviceManager(deviceManager);
		return getDataTable(list);
	}

	/*新增页面*/
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	/*保存新增机台*/
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(DeviceManager deviceManager) {
		return toAjax(deviceMapper.insertDeviceManager(deviceManager));
	}

	/*修改回显机台*/
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		DeviceManager deviceManager = deviceMapper.selectByPrimaryKey(id);
		mmap.put("DeviceManager", deviceManager);
	    return prefix + "/edit";
	}
	/*根据机台id查机台*/
	@PostMapping("/findItemById")
	@ResponseBody
	public DeviceManager findItemById(Integer id){
		return deviceMapper.findItemById(id);
	}

	/*修改保存机台*/
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(DeviceManager deviceManager) {
		return toAjax(deviceMapper.editSave(deviceManager));
	}
	
	/*删除机台*/
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(deviceMapper.deleteDeviceByIds(Convert.toStrArray(ids)));
	}
	
}
